<template>
	<view v-if="config.length!=0">
		<view class="main">
			<card-list v-for="(item,index) in config" :key='index' :config='item'></card-list>
		</view>
		<view class="clear">
			<u-button type="warning" shape="circle" @click="clear">全部清除</u-button>
		</view>
	</view>
	<view v-else class="noConfig">
		没有历史记录
	</view>
</template>

<script>
	export default {
		data() {
			return {
				state: 0,
				config: []
			}
		},
		onLoad() {
			const clock = uni.getStorageSync('clock')
			if (clock.length == 0) {
				this.stste = '没有内容'
				return;
			}
			this.getConfiglist(clock)
		},
		methods: {
			clear(){
				uni.showModal({
					title:'提示',
					content:'是否确认删除你的本地浏览记录',
					success(e) {
						if(e.confirm){
							uni.setStorageSync('clock',[])
							this.config = []
						}else{
							return
						}
					}
				})
			},
			getConfiglist(ids) {
				console.log(ids);
				ids.forEach(async (value) => {
					await wx.cloud.callFunction({
						name: "getTemplate",
						data: {
							_id: value,
							action: 'getTempitem'
						},
						success: res => {
							// console.log("请求成功", res.result);
							this.config.push(res.result.data)
							this.config.reverse()
						},
						fail: err => {
							console.log("请求失败", err)
						}
					})
				})
			}
		}
	}
</script>

<style>
	.main {
		width: 710rpx;
		margin: 0 20rpx;
	}
	.clear{
		margin: 0 20rpx 20rpx 20rpx;
	}
	.noConfig{
		padding: 20rpx;
		text-align: center;
	}
</style>
